#include "node.h"
#include <QPainter>
#include <QPainterPath>
Node::Node(qint32 width, qint32 height) : width(width), height(height)
{
    init();
}

QRectF Node::boundingRect() const
{
    return QRectF(0, 0, width, height);
}

void Node::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
    QPainterPath path;
    path.addRoundedRect(0, 0, width, height, 10, 10);
    QPen pen(QColor("#444"));
    pen.setWidth(4);
    if(isSelected()) {
        pen.setColor(QColor("#5aa"));
    }
    painter->setPen(pen);
    painter->drawPath(path);

    painter->fillPath(path, QBrush(QColor("#eee")));
}

void Node::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
    QGraphicsItem::mouseMoveEvent(event);
}

void Node::init()
{
    // 设置可选择可拖动
    setFlags(GraphicsItemFlag::ItemIsMovable | GraphicsItemFlag::ItemIsFocusable | GraphicsItemFlag::ItemIsSelectable
             );
    setEnabled(true);
}

Socket::Socket()
{

}

QRectF Socket::boundingRect() const
{
    return QRectF(0, 0, 0, 0);
}

void Socket::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{

}
